import { BasicDrawer, useDrawerInner } from "@/components/Drawer";
import { BasicColumn, BasicTable, useTable } from "@/components/Table";
import { processDefinitionPage } from "@/api/bpm/model";
import "./index.less";
import { useEffect } from "react";
import { Button, Tag } from "antd";
import { formatDate } from "@/utils/util";
import { useTranslation } from "react-i18next";
let key: String;
const index = (props: { register: Fn }) => {
	const { t } = useTranslation();
	const en_vi = "task.model";
	const columns: BasicColumn[] = [
		{
			title: t(`${en_vi}.definitionId`),
			dataIndex: "id"
		},
		{
			title: t(`${en_vi}.processName`),
			dataIndex: "name",
			render: (name: string) => {
				return <Button type="link">{name}</Button>;
			}
		},
		{
			title: t(`${en_vi}.cateName`),
			dataIndex: "cateName"
		},
		{
			title: t(`${en_vi}.formInformation`),
			dataIndex: "formCustomCreatePath",
			render: (formCustomCreatePath: string) => {
				return <Button type="link">{formCustomCreatePath}</Button>;
			}
		},
		{
			title: t(`${en_vi}.processVersion`),
			dataIndex: "version",
			render: (version: string) => {
				return <Tag color="processing">V{version}</Tag>;
			}
		},
		{
			title: t(`${en_vi}.status`),
			dataIndex: "suspensionState",
			render: (state: string) => {
				return state == "2" ? <Tag color="warning">{t(`${en_vi}.pending`)}</Tag> : "";
			}
		},
		{
			title: t(`${en_vi}.deploymentTime`),
			dataIndex: "deploymentTime",
			render: (time: any) => {
				return formatDate(new Date(time));
			}
		},
		{
			title: t(`${en_vi}.description`),
			dataIndex: "description"
		}
	];
	const [register, { reload }] = useTable({
		api: processDefinitionPage,
		columns,
		useSearchForm: false,
		bordered: false,
		beforeFetch: params => {
			params.key = key;
			return params;
		}
	});
	const [registerDrawer] = useDrawerInner(props.register, async data => {
		console.log(data.record);

		key = data.record.key;
	});
	useEffect(() => {
		reload();
	}, [key]);
	return (
		<BasicDrawer showFooter={false} size="large" {...props} register={registerDrawer}>
			<BasicTable register={register}></BasicTable>
		</BasicDrawer>
	);
};
export default index;
